function [linkDensities,linkStrength,linkDistances] = analyzeLinkMatrix(neuralGasMap)
    COSINE = neuralGasMap.COSINE;
    M=neuralGasMap.M;
    D=neuralGasMap.D;
    linkMatrix=neuralGasMap.linkMatrix;
    
    %extract link strength and density information
    linkStrength = zeros(size(linkMatrix));
    linkDensities = linkStrength;
    linkDistances = linkStrength;
    
    for bmu1=1:size(linkMatrix,1)
        for bmu2=1:size(linkMatrix,2)
            %extract link strength
            strength = getStrengthInformation(bmu1,bmu2,neuralGasMap);
            linkStrength(bmu1,bmu2) = strength;
            linkStrength(bmu2,bmu1) = strength;

            %extract density information    
            density = getDensityInformation(bmu1,bmu2,neuralGasMap);
            linkDensities(bmu1,bmu2) = density;
            linkDensities(bmu2,bmu1) = density;
            
            %extract distance information
            distanceRatio = getDistanceInformation(bmu1,bmu2,neuralGasMap);
            linkDistances(bmu1,bmu2) = distanceRatio;
            linkDistances(bmu2,bmu1) = distanceRatio;
        end
    end
    return
    
    
function [strength] = getStrengthInformation(bmu1,bmu2,neuralGasMap)
    linkMatrix = neuralGasMap.linkMatrix;
    linkMatrix = linkMatrix + 1;
    linkStrength = linkMatrix(bmu1,bmu2);
    
    strength=1;
    
            
    if (linkStrength > 0) 
        %get links from bmu1 and bmu2
        bmu1Links = linkMatrix(bmu1,:);
        bmu2Links = linkMatrix(bmu2,:);

        %remove links to each other
        bmu1Links(bmu2)=0;
        bmu2Links(bmu1)=0;

        %only keep links
        bmu1Links=bmu1Links(bmu1Links>0);
        bmu2Links=bmu2Links(bmu2Links>0);

        if ((isempty(bmu1Links)) || (isempty(bmu2Links)))
            strength = 1;
        else
            %max values
            maxBmu1LinkValue = max(bmu1Links);
            maxBmu2LinkValue = max(bmu2Links);

            %min values
            minBmu1LinkValue = min(bmu1Links);
            minBmu2LinkValue = min(bmu2Links);

            %mean values
            meanBmu1LinkValue = mean(bmu1Links);
            meanBmu2LinkValue = mean(bmu2Links);

            %mean calc
            meanRatio = meanBmu1LinkValue/meanBmu2LinkValue;
            if (meanRatio>1)
                meanRatio=1/meanRatio;
            end

            %min calc
            %minRatio = minBmu1LinkValue/minBmu2LinkValue;
            %if (minRatio>0)
            %    minRatio=1/minRatio;
            %end

            %max calc
            %maxRatio = maxBmu1LinkValue/maxBmu2LinkValue;
            %if (maxRatio>0)
            %    maxRatio=1/maxRatio;
            %end

            strength = meanRatio;
        end
    end;
    return
    
    
function [density] = getDensityInformation(bmu1,bmu2,neuralGasMap)
    M = neuralGasMap.M;
    D = neuralGasMap.D;
    linkMatrix = neuralGasMap.linkMatrix;
    COSINE = neuralGasMap.COSINE;
    linkStrength = linkMatrix(bmu1,bmu2);
    
    
    
    density = 1;
            
    if (linkStrength > -1) 
        %data-BMU hits/needed for 
        if (COSINE == 0)
            [dataHits,distances] = neuralGasBmus(M,D);
        else
            [dataHits,distances] = neuralGasBmusCosine(M,D);
        end
        
        
        bmu1HitIndeces = dataHits == bmu1;
        bmu2HitIndeces = dataHits == bmu2;

        value1 = min([sum(bmu1HitIndeces) sum(bmu2HitIndeces)]);
        value2 = max([sum(bmu1HitIndeces) sum(bmu2HitIndeces)]);

        density = value1/value2;
    end
    return
    
function [distanceRatio] = getDistanceInformation(bmu1,bmu2,neuralGasMap)
    M = neuralGasMap.M;
    D = neuralGasMap.D;
    linkMatrix = neuralGasMap.linkMatrix;
    COSINE = neuralGasMap.COSINE;
    
    %data-BMU hits/needed for 
    if (COSINE == 0)
        [dataHits,distances] = neuralGasBmus(M,D);
    else
        [dataHits,distances] = neuralGasBmusCosine(M,D);
    end
    
    distanceRatio=1;
    
    if (linkMatrix(bmu1,bmu2)>-1)
        %extract data vectors covered by the given unit
        unitHits = dataHits == bmu1;
        
        %get distances of data vectors to given unit
        data=distances(unitHits,:);
        
        %calc mean distance value
        meanData = mean(data);
        
        %extract data vectors covered by the linked unit
        linkedUnitHits = dataHits == bmu2;

        %calc distances of these vectors to the source unit
        if (COSINE == 0)
            [indeces, linkedData] = neuralGasBmus(M(bmu1,:),D(linkedUnitHits,:));
        else
            [indeces, linkedData] = neuralGasBmusCosine(M(bmu1,:),D(linkedUnitHits,:));
        end

        %calc mean distance value
        meanLinkedData = mean(linkedData);

        distanceRatio=meanData/meanLinkedData;
    end
    return    
    
   
  






